<template>
    <div class="main">
        <div id="index_top" class="index_top">
            <div class="index_login">
                <img :src="logoUrl" alt="">
            </div>
            <div class="dragClass">
                <div class="index_tit" id="appCName">{{index_tit}}</div>
                <div class="topSelectedSoft_btn" id="topSelectedSoft" @click="openswitchMenu">切换已开通科目</div>
            </div>
            <!--菜单列表-->


            <ul class="index_menu" @click="morePophide">
                <li id="liIndex" class="liIndex " @click="IndexClick" v-bind:class="{menu_on:index==1}">
                    <!--<i>宝典首页</i>-->
                </li>
                <li id="liChapterMenu" @click="ChapterMenuClick" v-bind:class="{ 'liChapterMenu': ischapter,'liChapterMenu1': !ischapter,  menu_on:index==2 }">
                    <!--<i>章节练习 综合练习</i>-->
                </li>
                <li id="liSimulation" v-if="" class="liSimulation" @click="SimulationClick" v-bind:class="{menu_on:index==3}">
                    <!--<i>模拟考场</i>-->
                </li>
                <li id="liConciseCourse" v-if="moduleshowData.course" class="liConciseCourse" @click="ConciseCourseClick" v-bind:class="{menu_on:index==4}">
                    <!--<i>课程精讲</i>-->
                </li>
                <!--<li id="liZSDSL">-->
                    <!--<i>知识点梳理</i>-->
                <!--</li>-->
                <li id="liSprint" @click="SprintClick" v-if="moduleshowData.chongci" v-bind:class="[chongcibao,{menu_on:index==5 }]">
                    <!--<i>提分加血</i>-->
                </li>
                <li id="liMND" v-if="moduleshowData.mianshen" class="liMNDB" @click="MNDBClick" v-bind:class="{menu_on:index==6}">
                    <!--<i>面审答辩</i>-->
                </li>
                <li id="liTestInfoMenu" class="liTestInfoMenu" @click="TestInfoMenuClick" v-bind:class="{menu_on:index==7}">
                    <!--<i>考试指南</i>-->
                </li>
                <li id="mywenguzhixin" class="mywenguzhixin" @click="wenguzhixinClick" v-bind:class="{menu_on:index==8}">
                    <!--<i>温故知新</i>-->
                </li>
                <li id="myCenter" class="myCenter" @click="myCenterClick" v-bind:class="{menu_on:index==9}">
                    <!--<i>个人中心</i>-->
                    <div style="display: none; width: 17px;" class="indexicn-new" >
                    <span id="indexnewNoRead"></span></div>
                </li>
                <!--更多...-->
                <li id="more_p" class="more_p" @click.stop="moreClick" v-bind:class="{menu_on:index==10}">
                    <div class="two" v-if="showmorePop">
                        <ul id="textImg">
                            <li id="service" class="serviceCenter" @click="serviceClick(1)">
                                <img src="../../images/kfzx.png" class="Imgone_xiala">
                                <span class="nosize">客服中心</span>
                            </li>
                            <li id="aboutSoft" @click="serviceClick(2)">
                                <img src="../../images/gywm.png" class="Imgone_xiala">
                                <span class="nosize">关于我们</span>
                            </li>
                        </ul>
                    </div>
                </li>
            </ul>
        </div>
        <div class="index_bottom" ref="index_bottom">
        	<indexPage v-bind:bottom_height ="bottom_height" v-if="index===1"></indexPage>
        	<personalMenu v-if="index===9"></personalMenu>
        	<!--<Simulation></Simulation>-->
        	<chapterMenu v-if="index===2" ref="" :mouduleUser="mouduleUser.BaseTest? mouduleUser.BaseTest.isVip : false"></chapterMenu>
            <services v-if="index===10"></services>
            <!--<Simulation></Simulation>-->
        	<!--<conciseCourse></conciseCourse>-->
        	<!--<Sprint></Sprint>-->

        </div>
        <switchMenu v-if="showSwitch" @click="closeswitchMenu"></switchMenu>
    </div>
</template>
<script>
    import switchMenu from "../account/children/switchMenu.vue";
    import { getCookie,getAppEName ,getAppName,getAppID,getAppAppVName,compareObj,compareTime,category} from "../../config/mUtils";
    import { getVipSoft,getSprintConfig,getAppsubject } from "../../config/getData";
    import {G_agentUrl} from '../../config/global'
    import indexPage from "./children/indexPage.vue";
    import chapterMenu from "./children/chapterMenu.vue";
    import personalMenu from "./children/personalMenu.vue";
    import services from "./children/services.vue";
    export default {
    	name :'mainIndex',
    	components: {
	        indexPage,  // 登录
            switchMenu,//切换科目
            chapterMenu,//章节练习
            personalMenu,//个人中心
            services,//客服中心
//	        remoteJS: {  // 验证码js
//	            render(createElement) {
//	                return createElement('script', { attrs: { type: 'text/javascript', src: this.src } });
//	            },
//	            props: {
//	                src: { type: String, required: true },
//	            },
//	        }
	    },
        data: function() {
            return {
                showSwitch:false,
                logoUrl:require('../../images/logo.png'), //不同代理商的logo
                showmorePop:false,
                currentIndex:0,
                index:1,
                bottom_height:'',
                index_tit:'正在获取数据...',
                ischapter:true,
                chongcibao:'liChongcibao',
                moduleshowData :{
                    'course':false,
                    'chongci':false,
                    'mianshen':false
                },
                moduleDiv:{
                    'index':true,
                    'chapter':false,
                },
                mouduleUser:'',
                moreIndex:0,



            }
        },
        methods: {
            openswitchMenu:function(){
                this.showSwitch = true;
            },
            closeswitchMenu:function(){
                this.showSwitch = false;
            },
            backUrl: function(){
                this.$router.push('/login');
            },
            showlogo:function () {
                let agentCode = getCookie('AGENTCODE');//cookie中取
                if(agentCode === '101021-2'){
                    this.logoUrl = require('../../images/agentimg/101021-2/logo_img.png');
                }else if(agentCode === '076901'){
                    this.logoUrl = require('../../images/agentimg/076901/top_logo.png');
                }else if(agentCode === '057303'){
                    this.logoUrl = require('../../images/agentimg/examination.png');
                }else if(host === 'www.kaiedu.com' || agentCode==='021028'){
                    this.logoUrl = require('../../images/agentimg/logo021028.png');
                }
            },
            showTitle(){
                let _appEName = getAppEName();
                let _appID = getAppID();
                let _appName = getAppName();
                let _appVName = getAppAppVName();
                let guid = localStorage.getItem('guid')
                let jsonData = '';
                let _appENameNew = '';
                let appinfo = [];//当前科目的购买信息
                let appinfonew = [];//当前科目的未过期的购买信息
                if(_appEName.indexOf('_YTMJ') > -1){
                    _appENameNew = _appEName.split('_YTMJ')[0]; // 基础版的appEName
                }else{
                    _appENameNew = _appEName +'_YTMJ';
                }
                getVipSoft(guid).then(res => {
                    if(res.status===200){
                        jsonData = res.data.VipApp;
                        if(jsonData.length === 0){
                            this.index_tit = _appName + '-'+ '试用';
                        }else{
                            for(let i = 0 ;i< jsonData.length ;i++){
                                if(jsonData[i].AppEName && (jsonData[i].AppEName == _appEName || jsonData[i].AppEName == _appENameNew)){
                                    appinfo.push(jsonData[i]);
                                }
                            }
                            if(appinfo.length === 0){
                                this.index_tit = _appName + '-'+ '试用';
                            }else{
                                for(let j = 0;j< appinfo.length ;j++){
                                    console.log(compareTime(appinfo[j].EndTime))
                                    appinfonew.push(appinfo[j])
                                }
                                appinfonew = appinfonew.sort(compareObj('VnOrder'));
                                this.index_tit = _appName + '-'+ appinfonew[appinfonew.length-1].AppVnName
                            }
                        }
                    }
                })
            },
            topmoduleShow:function () {
                let _appEName = getAppEName();
                let _appName = getAppName();
                let AppVerOperJSON = getCookie('AppVerOperJSON');
                let appversionData = '';
                if(AppVerOperJSON && JSON.parse(AppVerOperJSON) && JSON.parse(AppVerOperJSON).VerJSON){
                    appversionData = JSON.parse(AppVerOperJSON).VerJSON;
                }
                let hasBetExam = appversionData.hasBetExam ; //押题密卷
                let hasSpeakPoint = appversionData.hasSpeakPoint ; // 考点精讲
                let hasSpeakError = appversionData.hasSpeakError ; // 错题精讲
                let hasSprintTest = appversionData.hasSprintTest ;
                let hasCombingPoint2 = appversionData.hasCombingPoint2 ;
                let hasSprintOldExam =appversionData.hasSprintOldExam ; //真题精讲
                let hasSprintPackage =appversionData.hasSprintPackage ;//提分加血 /考前冲刺包
                let hasPaperVideo = appversionData.hasPaperVideo ; // 论文答辩
                let hasGrabpoints = appversionData.hasGrabpoints ;// 抢分3000 /抢分1000
                let hasYMLJPTest = appversionData.hasYMLJPTest ; //一模测评
                let hasYMLJPVideo = appversionData.hasYMLJPVideo ;// (一模视频)  一模练讲评
                let hasSJPD = appversionData.hasSJPD ; //私教班判断

                let hasgpkdcck = appversionData.hasgpkdcck;//高频考点冲刺课
                let haskdlxt = appversionData.haskdlxt;//考点练习题 (考点精讲)
                let hasmsqtfdk = appversionData.hasmsqtfdk;//名师圈题辅导课
                let hasyhyczxlx = appversionData.hasyhyczxlx;//易混易错专项练习(错题精讲 易混易错培训课)
                let haszdaljjk = appversionData.haszdaljjk;//重点案例精讲课
                let hasalzxlx = appversionData.hasalzxlx;//案例专项练习(重点案例精讲课)
                let hasDefend = appversionData.hasDefend;//面审

                if(_appEName){
                    if(_appEName.indexOf('ZCJSJ') === -1){

                    }else if(_appEName.indexOf('ZCJSJ') === 0){

                    }

                }

                if(hasSpeakPoint || hasSpeakError || hasSprintOldExam || (hasPaperVideo && G_agentUrl === 'wide.ksbao.com') || hasYMLJPTest || hasYMLJPVideo || hasgpkdcck || hasmsqtfdk || haszdaljjk){
                    this.moduleshowData.course = true;
                }
                if(hasBetExam || hasSprintPackage){
                    this.moduleshowData.chongci = true;
                }
                if(hasDefend){
                    this.moduleshowData.mianshen = true;
                }

                if(_appName.indexOf('正高')>-1 || _appName.indexOf('副高')>-1){
                    this.ischapter = false;
                    this.chongcibao = 'liTeacher';//名师点题卷
                }else if(category() === 'chuji' || category() === 'zhongji'){
                    this.chongcibao ='liSprint';//提分加血
                }else if(hasSprintPackage){
                    this.chongcibao ='liChongcibao';//考前冲刺包
                    getSprintConfig(_appEName).then(res=>{
                        if(res.status === 200 && res.data.Childs && res.data.Childs._length === 1 && res.data.Childs[0].flag=== 'txmj'){
                            this.chongcibao ='liTxmj'
                        }
                    })

                }else{
                    this.chongcibao ='liTxmj'
                }
            },
            IndexClick:function(){
            	this.index = 1;
            },
            ChapterMenuClick:function(){
            	this.index = 2;
            },
            SimulationClick:function(){
            	this.index = 3;
            },
            ConciseCourseClick:function(){
            	this.index = 4;
            },
            SprintClick:function(){
            	this.index = 5;
            },
            MNDBClick:function(){
            	this.index = 6;
            },
            TestInfoMenuClick:function(){
            	this.index = 7;
            },
            wenguzhixinClick:function(){
            	this.index = 8;
            },
            myCenterClick:function(){
            	this.index = 9;
            },
            moreClick:function(){
            	this.showmorePop = true ;
            	this.index = 10;
            },
            morePophide:function(){
            	this.showmorePop = false ;
            },
            serviceClick:function(_index){
                this.moreIndex = _index;
            },
            getmoduleInfo(){
                let appID = getAppID();
                let guid = localStorage.getItem('guid')
                getAppsubject(appID,guid,0).then(res=>{
                    if(res.status===200){
                        this.mouduleUser = res.data;
                    }
                })
            }
        },
        mounted: function() {
            this.showlogo();
            this.showTitle();//显示科目名称
            this.topmoduleShow();
            this.getmoduleInfo();
            let height_1=  Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);

            this.bottom_height = height_1 - 112;
            this.bottom_height1 = window.innerHeight - 112;

            this.$refs.index_bottom.style.height = this.bottom_height1+ 'px';
            window.onresize = () => {
                return (() => {
                    this.bottom_height1 = window.innerHeight - 112;
                    let height_1=  Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
                    this.bottom_height = height_1 - 112 > 500  ? 500:  height_1 - 112;
                    this.$refs.index_bottom.style.height = this.bottom_height1+ 'px';
                })()
            }

        }
    }

</script>
<style lang="less">
    @import "./maintop.less";
</style>
